﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class UserControls_register : System.Web.UI.UserControl
{


    SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
    SqlOperate sqloperate = new SqlOperate();

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void submitButton_Click(object sender, EventArgs e)
    {
        string name = useridTextBox.Text;
        string password = passwordTextBox.Text;
        string email = emailTextBox.Text;
        string telephone = phoneTextBox.Text;
        string address = addressTextBox.Text;
        string postcode = postcodeTextBox.Text;
        DateTime createdate = DateTime.Now;
        char state = '0';
        string remark = remarkTextBox.Text;

        //==
        {
            string sqltest = "select * from UserInfo where Name='" + name + "'";
            sqlconn.Open();
            SqlCommand sqlcom = new SqlCommand(sqltest, sqlconn);
            SqlDataReader read = sqlcom.ExecuteReader();
            read.Read();
            if (read.HasRows)
            {
                if (name.Trim() == read["Name"].ToString().Trim())
                {
                    Response.Write("<script language='javascript'>alert('该会员已经注册过');localtion='register.aspx'</script>");
                    return;
                }
            }
            string sqlstr = "insert into UserInfo "
                + "(Name,Password,Mail,Telephone,Address,Postcode,Createdate,State,Remark)"
                + "values('" + name + "','" + password + "','" + email + "','" + telephone + "','" + address + "','" + postcode + "','" + createdate + "','" + state + "','" + remark + "')";
            sqloperate.DataCom(sqlstr);
            sqlconn.Close();
            Session["regName"] = name.Trim();
            Response.Redirect("Default.aspx");
        }

        //==
    }
    protected void cancelButton_Click(object sender, EventArgs e)
    {

    }
}